#!/usr/bin/env python
# encoding: utf-8

import torch
import argparse
import numpy as np
import soundfile as sf
import torchaudio
import torch
from multiprocessing import Pool

parser = argparse.ArgumentParser()
parser.add_argument('--data_list', help='data list', type=str, default="data/dev_list")
args = parser.parse_args()

def vad(filename):
    save_path = filename.strip(".wav") + ".pt"
    waveform, sample_rate = sf.read(filename)
    waveform = torch.from_numpy(waveform)
    waveform = torchaudio.functional.vad(waveform=waveform, sample_rate=sample_rate)
    torch.save(waveform, save_path)

if __name__ == "__main__":
    audio_seq, speaker = torch.load(args.data_list)
    data_paths = np.array(audio_seq).T[1].tolist()
    with Pool(16) as p:
        p.map(vad, data_paths)



